package org.yds.quality.function;

import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.type.AviatorObject;

import java.util.Map;

public class IfFunction extends AbstractFunction {

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject condition, AviatorObject trueValue, AviatorObject falseValue) {
        // 获取条件值
        boolean conditionResult = (boolean) condition.getValue(env);

        // 根据条件返回对应的值
        if (conditionResult) {
            return trueValue;
        } else {
            return falseValue;
        }
    }

    @Override
    public String getName() {
        return "IF"; // 函数名称
    }
}
